package com.example.imoocmall.controller;

import com.example.imoocmall.common.ApiRestResponse;
import com.example.imoocmall.model.pojo.Product;
import com.example.imoocmall.model.request.ProductListReq;
import com.example.imoocmall.service.impl.ProductServiceImpl;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 前台商品controllor
 */
@RestController
@Api(tags = "商品管理")
public class ProductContruller {

    @Autowired
    ProductServiceImpl productService;

    @ApiOperation("商品详情")
    @PostMapping("/product/detail")
    public ApiRestResponse detail(@RequestParam Integer id){
        Product product = productService.detail(id);
        return ApiRestResponse.success(product);
    }

    @ApiOperation("商品搜索")
    @PostMapping("/product/search")
    public ApiRestResponse search(@RequestBody ProductListReq productListReq){

        PageInfo list = productService.search(productListReq);
        return ApiRestResponse.success(list);

    }
}
